//
//  YXSignInViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-5-5.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXSignInViewController.h"

@interface YXSignInViewController ()

@end

@implementation YXSignInViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_mapView viewWillAppear];
    _mapView.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated
{
    _mapView.delegate = nil;
    [_mapView setShowsUserLocation:NO];
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _signInVi = [[YXSignInView alloc] init];
    self.view = _signInVi;
    
    
    _isUpdate = YES;
    _mapView = [[BMKMapView alloc] initWithFrame:CGRectZero];
    [_mapView setUserTrackingMode:BMKUserTrackingModeNone];
    [_mapView setShowsUserLocation:YES];
    [self.view addSubview:_mapView];
    [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"正在定位中，请稍后。。。"];
}

#pragma mark - BMKMapViewDelegate
- (void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation
{
    if (_isUpdate) {
        _isUpdate = NO;
        [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"拜访成功。"];
        [_mapView setShowsUserLocation:NO];
    }
}

- (void)mapView:(BMKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
    [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"定位失败！！"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
